import os, geopandas as gpd
import matplotlib.pyplot as plt
departments=gpd.read_file(os.path.join("maps","Departamentos","departamentos_geo.shp"))
rivers=gpd.read_file(os.path.join("maps","Rios","Rios.shp"))
cities=gpd.read_file(os.path.join("maps","Ciudades","CapitalDepartamental.shp"))
type(departments)
geopandas.geodataframe.GeoDataFrame
type(rivers)
geopandas.geodataframe.GeoDataFrame
type(cities)
geopandas.geodataframe.GeoDataFrame
departments.shape
(9, 4)
rivers.shape
(940, 5)
cities.shape
(9, 4)
departments.head()
| id | c_ut | DEPARTAMEN | geometry | |
|---|---|---|---|---|
| 0 | 0 | 03 | Cochabamba | POLYGON ((-65.79998 -18.00967, -65.80067 -18.0... |
| 1 | 1 | 05 | Potosí | POLYGON ((-66.68310 -18.48254, -66.68310 -18.4... |
| 2 | 2 | 06 | Tarija | POLYGON ((-65.05251 -22.08335, -65.13966 -22.0... |
| 3 | 3 | 07 | Santa Cruz | POLYGON ((-57.63652 -17.98160, -57.61941 -18.0... |
| 4 | 4 | 09 | Pando | POLYGON ((-69.00170 -11.00922, -69.00106 -11.0... |
rivers.head()
| gml_id | ID | NOMBRE | RIOS_LIM | geometry | |
|---|---|---|---|---|---|
| 0 | Rios.1 | 0 | Río Kharamanu | NaN | LINESTRING (-67.70626 -10.69996, -67.70825 -10... |
| 1 | Rios.2 | 0 | Río Paucerna | NaN | LINESTRING (-60.81141 -14.27497, -60.80161 -14... |
| 2 | Rios.3 | 0 | Río Supaymanu | NaN | LINESTRING (-68.56330 -11.46430, -68.56529 -11... |
| 3 | Rios.4 | 0 | NaN | NaN | LINESTRING (-68.92574 -11.17870, -68.92760 -11... |
| 4 | Rios.5 | 0 | NaN | NaN | LINESTRING (-66.50216 -10.69610, -66.50555 -10... |
cities.head()
| gml_id | ID | NOMBRE | geometry | |
|---|---|---|---|---|
| 0 | CapitalDepartamental.1 | 0 | COBIJA | POINT (-68.77689 -11.03397) |
| 1 | CapitalDepartamental.2 | 0 | TRINIDAD | POINT (-64.92070 -14.84987) |
| 2 | CapitalDepartamental.3 | 0 | LA PAZ | POINT (-68.13798 -16.49165) |
| 3 | CapitalDepartamental.4 | 0 | COCHABAMBA | POINT (-66.17044 -17.38918) |
| 4 | CapitalDepartamental.5 | 0 | ORURO | POINT (-67.11293 -17.96623) |
departments.info()
<class 'geopandas.geodataframe.GeoDataFrame'> RangeIndex: 9 entries, 0 to 8 Data columns (total 4 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 id 9 non-null int64 1 c_ut 9 non-null object 2 DEPARTAMEN 9 non-null object 3 geometry 9 non-null geometry dtypes: geometry(1), int64(1), object(2) memory usage: 416.0+ bytes
rivers.info()
<class 'geopandas.geodataframe.GeoDataFrame'> RangeIndex: 940 entries, 0 to 939 Data columns (total 5 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 gml_id 940 non-null object 1 ID 940 non-null int64 2 NOMBRE 189 non-null object 3 RIOS_LIM 13 non-null object 4 geometry 940 non-null geometry dtypes: geometry(1), int64(1), object(3) memory usage: 36.8+ KB
cities.info()
<class 'geopandas.geodataframe.GeoDataFrame'> RangeIndex: 9 entries, 0 to 8 Data columns (total 4 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 gml_id 9 non-null object 1 ID 9 non-null int64 2 NOMBRE 9 non-null object 3 geometry 9 non-null geometry dtypes: geometry(1), int64(1), object(2) memory usage: 416.0+ bytes
departments.plot()
rivers.plot()
cities.plot()
<AxesSubplot:>
departments.crs
<Geographic 2D CRS: GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84" ...> Name: WGS 84 Axis Info [ellipsoidal]: - lon[east]: Longitude (Degree) - lat[north]: Latitude (Degree) Area of Use: - undefined Datum: World Geodetic System 1984 - Ellipsoid: WGS 84 - Prime Meridian: Greenwich
rivers.crs
<Geographic 2D CRS: GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84" ...> Name: WGS 84 Axis Info [ellipsoidal]: - lon[east]: Longitude (Degree) - lat[north]: Latitude (Degree) Area of Use: - undefined Datum: World Geodetic System 1984 - Ellipsoid: WGS 84 - Prime Meridian: Greenwich
cities.crs
<Geographic 2D CRS: GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84" ...> Name: WGS 84 Axis Info [ellipsoidal]: - lon[east]: Longitude (Degree) - lat[north]: Latitude (Degree) Area of Use: - undefined Datum: World Geodetic System 1984 - Ellipsoid: WGS 84 - Prime Meridian: Greenwich
base = departments.plot(facecolor="white", edgecolor='black', linewidth=0.5,figsize=(12,12))
cities.plot(marker='D', color='red', markersize=15,alpha=1,
ax=base)
rivers.plot(edgecolor='blue', linewidth=0.35,
ax=base)
<AxesSubplot:>
crs = 'EPSG:4326'
departments.crs = crs
rivers.crs = crs
cities.crs = crs
import folium
m = cities.explore(color="red",
name="cities")#optional
m = rivers.explore(m=m, color="blue",
name="rivers")#optional
#folium.LayerControl().add_to(m) #optional
m
la_paz=departments[departments.DEPARTAMEN=='La Paz']
cities_clipped = gpd.clip(gdf=cities,
mask=la_paz)
rivers_clipped = gpd.clip(gdf=rivers,
mask=la_paz)
base = la_paz.plot(facecolor="greenyellow", edgecolor='black', linewidth=0.4,figsize=(5,5))
cities_clipped.plot(marker='+', color='red', markersize=15,ax=base)
rivers_clipped.plot(edgecolor='blue', linewidth=0.5,ax=base)
<AxesSubplot:>
la_pazCoord=[-16.5, -68.15]
m = cities.explore(location=la_pazCoord,
zoom_start=10,
tiles='CartoDB positron',
color='red',
name="cities") #optional
m = rivers.explore(m=m, color="blue",
name="rivers")#optional
# folium.LayerControl().add_to(m) #optional
m
base = la_paz.plot(facecolor="lightgreen", edgecolor='black', linewidth=0.4,figsize=(5,5))
map2=cities_clipped.plot(marker='D', color='red', markersize=15,ax=base)
mapEnd=rivers_clipped.plot(edgecolor='blue', linewidth=0.5,ax=base)
plt.savefig(os.path.join("maps",'mapEnd.jpg'))
departments.to_file(os.path.join("maps","worldMaps.gpkg"), layer='departments', driver="GPKG")
cities.to_file(os.path.join("maps","worldMaps.gpkg"), layer='cities', driver="GPKG")
rivers.to_file(os.path.join("maps","worldMaps.gpkg"), layer='rivers', driver="GPKG")
worldMaps='https://github.com/FabianRomero20/Examen1.2/raw/main/maps/worldMaps.gpkg'
from fiona import listlayers
listlayers(worldMaps)
['departments', 'cities', 'rivers']
departments=gpd.read_file(worldMaps,layer='departments')
cities=gpd.read_file(worldMaps,layer='cities')
rivers=gpd.read_file(worldMaps,layer='rivers')
base = departments.plot(facecolor='gainsboro')
cities.plot(ax=base, markersize=0.5, color='red')
rivers.plot(ax=base, linewidth=0.5)
<AxesSubplot:>